//
//  XLStatusCell.swift
//  SinaWeibo
//
//  Created by 李凯 on 16/9/6.
//  Copyright © 2016年 kevin. All rights reserved.
//

import UIKit

// cell里面共有的间距
let HMStatusCellMargin: CGFloat = 10

class XLStatusCell: UITableViewCell {
    
    
    var statusViewModel: XLStatusViewModel? {
        didSet {
            originalView.statusViewModel = statusViewModel
            statusToolBar.statusViewModel = statusViewModel
            if statusViewModel?.status?.retweeted_status != nil{
                //显示
                retweetView.isHidden = false
                retweetView.statusViewModel = statusViewModel
                //更新工具条的约束
                statusToolBar.snp_remakeConstraints(closure: { (make) in
                    make.top.equalTo(retweetView.snp_bottom)
                    make.left.right.bottom.equalTo(contentView)
                    //make.height.equalTo(35)
                })
            }else{
                //隐藏
                retweetView.isHidden = true
                statusToolBar.snp_remakeConstraints(closure: { (make) in
                    make.top.equalTo(originalView.snp_bottom)
                    make.left.right.bottom.equalTo(contentView)
                    //make.height.equalTo(35)
                })
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        //设置cell选中样式
        selectionStyle = .none
        
        contentView.backgroundColor = UIColor.lightGray

        //添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(statusToolBar)
        contentView.addSubview(retweetView)
        //添加约束
        originalView.snp_makeConstraints { (make) in
            make.top.equalTo(contentView).offset(HMStatusCellMargin)
            make.left.right.equalTo(contentView)
            //make.bottom.equalTo(contentView)
            //make.height.equalTo(80)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            make.left.right.equalTo(originalView)
            make.top.equalTo(originalView.snp_bottom)
        }
        
        statusToolBar.snp_makeConstraints { (make) in
            make.top.equalTo(originalView.snp_bottom)
            make.left.right.bottom.equalTo(contentView)
            //make.height.equalTo(35)
        }
    }

    //懒加载
    lazy var originalView: XLOriginalStatusView = XLOriginalStatusView()
    lazy var statusToolBar: XLStatusToolBar = XLStatusToolBar()
    lazy var retweetView: XLRetweetStatusView = XLRetweetStatusView()
    
}
